package com.computergames.server.message;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;


import com.computergames.server.message.cardMessage.BidRequestMessage;
import com.computergames.server.message.cardMessage.BidResponseMessage;
import com.computergames.server.message.cardMessage.DealMessage;
import com.computergames.server.message.chessMessage.GobangMessage;
import com.computergames.server.message.cardMessage.LandlordMessage;

@Data
public abstract class Message implements Serializable {
    public static Class<?> getMessageClass(int messageType){
        return messageClasses.get(messageType);
    }

    private int sequenceId;
    private int messageType;

    public abstract int getMessageType();

    public static final int LoginRequestMessage = 0;
    public static final int LoginResponseMessage = 1;
    public static final int LoginPromptMessage = 2;
    public static final int ModeSelectionRequestMessage = 3;
    public static final int ModeSelectionResponseMessage = 4;
    public static final int StageSelectionRequestMessage = 5;
    public static final int StageSelectionResponseMessage = 6;
    public static final int CreateRoomRequestMessage = 7;
    public static final int CreateRoomResponseMessage = 8;
    public static final int JoinRoomRequestMessage = 9;
    public static final int JoinRoomResponseMessage = 10;
    public static final int QuitRoomRequestMessage = 11;
    public static final int QuitRoomResponseMessage = 12;
    public static final int RoomMembersRequestMessage = 13;
    public static final int RoomMembersResponseMessage = 14;
    public static final int ReadyRequestMessage = 15;
    public static final int ReadyResponseMessage = 16;
    public static final int MoveRequestMessage = 17;
    public static final int MoveResponseMessage = 18;
    public static final int MatchingRequestMessage = 19;
    public static final int MatchingResponseMessage = 20;
    public static final int PingMessage = 21;
    public static final int PongMessage = 22;
    public static final int ErrorResponseMessage = 23;
    public static final int AcknowledgeMessage = 24;
    public static final int DealMessage = 25;
    public static final int BidRequestMessage = 26;
    public static final int BidResponseMessage = 27;
    public static final int GobangMessage = 28;
    public static final int LandlordMessage = 29;
    public static final int ReconnectRequestMessage = 30;
    public static final int ReconnectResponseMessage = 31;

    private static final Map<Integer, Class<?>> messageClasses = new HashMap<>();
    static {
        messageClasses.put(LoginRequestMessage, LoginRequestMessage.class);
        messageClasses.put(LoginResponseMessage, LoginResponseMessage.class);
        messageClasses.put(LoginPromptMessage, LoginPromptMessage.class);
        messageClasses.put(StageSelectionRequestMessage, StageSelectionRequestMessage.class);
        messageClasses.put(StageSelectionResponseMessage, StageSelectionResponseMessage.class);
        messageClasses.put(ModeSelectionRequestMessage, ModeSelectionRequestMessage.class);
        messageClasses.put(ModeSelectionResponseMessage, ModeSelectionResponseMessage.class);
        messageClasses.put(CreateRoomRequestMessage, CreateRoomRequestMessage.class);
        messageClasses.put(CreateRoomResponseMessage, CreateRoomResponseMessage.class);
        messageClasses.put(JoinRoomRequestMessage, JoinRoomRequestMessage.class);
        messageClasses.put(JoinRoomResponseMessage, JoinRoomResponseMessage.class);
        messageClasses.put(QuitRoomRequestMessage, QuitRoomRequestMessage.class);
        messageClasses.put(QuitRoomResponseMessage, QuitRoomResponseMessage.class);
        messageClasses.put(RoomMembersRequestMessage, RoomMembersRequestMessage.class);
        messageClasses.put(RoomMembersResponseMessage, RoomMembersResponseMessage.class);
        messageClasses.put(ReadyRequestMessage, ReadyRequestMessage.class);
        messageClasses.put(ReadyResponseMessage, ReadyResponseMessage.class);
        messageClasses.put(MatchingRequestMessage, MatchingRequestMessage.class);
        messageClasses.put(MatchingResponseMessage, MatchingResponseMessage.class);
        messageClasses.put(MoveRequestMessage, MoveRequestMessage.class);
        messageClasses.put(MoveResponseMessage, MoveResponseMessage.class);
        messageClasses.put(ErrorResponseMessage, ErrorResponseMessage.class);
        messageClasses.put(AcknowledgeMessage, AcknowledgeMessage.class);
        messageClasses.put(DealMessage, DealMessage.class);
        messageClasses.put(BidRequestMessage, BidRequestMessage.class);
        messageClasses.put(BidResponseMessage, BidResponseMessage.class);
        messageClasses.put(GobangMessage, GobangMessage.class);
        messageClasses.put(LandlordMessage, LandlordMessage.class);
        messageClasses.put(ReconnectRequestMessage, ReconnectRequestMessage.class);
        messageClasses.put(ReconnectResponseMessage, ReconnectResponseMessage.class);
    }
}
